package com.zhangtai.modules.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.OverworkOodDto;
import com.zhangtai.modules.entity.employee.EmployeeOverworkOodEntity;
import com.zhangtai.modules.vo.EmployeeOverworkOodVo;
import com.zhangtai.modules.vo.EmployeeOverworkVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-12-15 17:01:39
 */
@Mapper
public interface EmployeeOverworkOodDao extends BaseMapper<EmployeeOverworkOodEntity> {


    @Select("<script>" +
            "Select r.* from tb_employee_overwork_ood r " +
            "left join tb_employee_info i on i.oid = r.oid " +
            "<where>   r.is_delete = 0 " +
            "<if test='orgName!=null and orgName!=&apos;&apos;'>and r.org_name like '%${orgName}%' </if>" +
            "<if test='unitName!=null and unitName!=&apos;&apos;'>and r.unit_name like '%${unitName}%' </if>" +
            "<if test='oprationName!=null and oprationName!=&apos;&apos;'>and r.opration_name like '%${oprationName}%' </if>" +

            "<if test='orgIds!=null and orgIds.size>0'> and r.unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+

            "<if test='orgIds==null or orgIds.size==0'> and (r.unit_id = null or r.oid = #{oid}) </if>" +

            "</where>" +
            " order by create_time desc" +
            "</script>")
    List<EmployeeOverworkOodVo> getOddHr(@Param("oprationName") String oprationName, @Param("orgName") String orgName
            , @Param("unitName") String unitName, Page<EmployeeOverworkOodVo> page, @Param("orgIds")List<Long> orgIds);

    @Select("select * from tb_employee_overwork_ood t1 left JOIN tb_employee_overwork_sub_odd t2 on t1.id =t2.teoo_id\n" +
            "where t1.opration_id= #{usercode}")
    List<OverworkOodDto> getOddDto(@Param("usercode") String usercode, Page<OverworkOodDto> page);
}